package com.hzj.controller;

import com.hzj.pojo.UserInfo;
import com.hzj.pojo.vo.user.LoginVo;
import com.hzj.pojo.vo.user.UserAuthVo;
import com.hzj.service.UserService;
import com.hzj.utils.RedisUtil;
import com.hzj.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/platformapi/user/")
public class UserController {
    @Autowired
    UserService us;
    @Autowired
    RedisUtil redisUtil;

    @PostMapping("/login")
    Result loginUser(@RequestBody LoginVo loginVo) {

        Map<String, Object> map = us.loginUser(loginVo);


//        UserInfo userInfo = (UserInfo) redisUtil.get("userInfo");
//        System.err.println("===" + userInfo.getName());


        map.remove("userInfo");

        return Result.ok(map);
    }

    @PostMapping("/auth/getUserInfo")
    Result getUserInfo() {
        return us.getUserInfo();
    }


    @PostMapping("/auth/userAuah")
    Result userAuah(@RequestBody UserAuthVo userAuthVo) {
        return us.userAuah(userAuthVo);
    }

    @PostMapping("/auth/updateUserMail")
    Result updateUserMail(@RequestParam("eamil") String email,@RequestParam String pass){
        return us.updateUserMail(email,pass);
    }


    @RequestMapping("/testuser")
    String testuser() {
        UserInfo userInfo = new UserInfo();
        userInfo.setName("爸爸");
        redisUtil.set("useraaa", userInfo);
        Object useraaa = redisUtil.get("useraaa");
        System.err.println("===" + useraaa);
        UserInfo user = (UserInfo) useraaa;
        System.err.println("name:" + user.getName());
        return "成功";
    }


}
